//This file is a part of StoragePlug for Minecraft.
//http://code.google.com/p/minecraft-storageplug/
//StoragePlug is Copyright (C) 2011 Christopher Smith
//Released under the MIT license:
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights 
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//DEALINGS IN THE SOFTWARE.
//
//Related to Minecraft Copyright (C) 2009-2011 Mojang http://www.minecraft.net/

package net.minecraft.storageplug;

//key class set up to have a finite number of concrete implementations
public abstract class Key
{
    private Key()
    {}
    
    public final static class ItemData
        extends Key
    {
        public final String name;

        public ItemData(String name)
        {
            this.name = name;
        }

        @Override
        public int hashCode()
        {
            return name.hashCode();
        }

        @Override
        public boolean equals(Object o)
        {
            return o instanceof Key.ItemData && name.equals(((Key.ItemData)o).name);
        }
    }
    
    public final static class Player
        extends Key
    {
        public final String name;

        public Player(String name)
        {
            this.name = name;
        }
        
        @Override
        public int hashCode()
        {
            return name.hashCode();
        }

        @Override
        public boolean equals(Object o)
        {
            return o instanceof Key.Player && name.equals(((Key.Player)o).name);
        }
    }
    
    public final static class Chunk
        extends Key
    {
        public final int dimension;
        public final int x;
        public final int z;

        public Chunk(int dimension, int x, int z)
        {
            this.dimension = dimension;
            this.x = x;
            this.z = z;
        }
        
        @Override
        public int hashCode()
        {
            int hash = 23;
            hash = hash * 37 + dimension;
            hash = hash * 37 + x;
            hash = hash * 37 + z;
            return hash;
        }

        @Override
        public boolean equals(Object o)
        {
            if(!(o instanceof Key.Chunk))
                return false;
            
            Chunk oc = (Key.Chunk)o;
            
            return dimension == oc.dimension && x == oc.x && z == oc.z;
        }
    }
    
    public final static class WorldInfo
        extends Key
    {
        @Override
        public int hashCode()
        {
            return 0x384ABFF3;
        }
        
        @Override
        public boolean equals(Object o)
        {
            return o instanceof Key.WorldInfo;
        }
    }
}
